package com.baidu.user.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baidu.user.dao.ClassMapper;
import com.baidu.user.entity.Class;
import com.baidu.user.service.ClassService;

@Service
public class ClassServiceImpl implements ClassService{

	@Autowired
	private ClassMapper classMapper ;
	
	public List<Class> getClassAll() {
		// TODO Auto-generated method stub
		return classMapper.findAll();
	}

	public void insertClazz(Class clazz) {
		// TODO Auto-generated method stub
		classMapper.insert(clazz);
	}

	public Map<String, Object> findByPageAndTxt(Integer page, Integer rows,
			String sort, String order) {
		// TODO Auto-generated method stub
		if(page!=null&&rows!=null){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("start", (page-1)*rows); //起始纪录数
			map.put("end", page*rows);//结束记录数
			if(sort!=null&&order!=null&&!sort.equals("")&&!order.equals("")){
				map.put("sort", sort);
				map.put("order", order);
			}
			List<Object> list = classMapper.findByPage(map);
			int count = classMapper.getListCount();
			Map<String, Object> data = new HashMap<String, Object>();
			data.put("total", count);
			data.put("rows", list);
			return data;
		}
		return null;
	}

	public void editClazz(Class clazz) {
		// TODO Auto-generated method stub
		classMapper.updateById(clazz);
	}

}
